Generic Attribute Profile (GATT) 您所在的位置:网站首页 Zephyr API Documentation Generic Access Profile GAP Generic Attribute Profile (GATT)

Generic Attribute Profile (GATT)

2024-05-18 17:12| 来源: 网络整理| 查看: 265

Generic Attribute Profile (GATT)露

GATT layer manages the service database providing APIs for service registration and attribute declaration.

Services can be registered using bt_gatt_service_register() API which takes the bt_gatt_service struct that provides the list of attributes the service contains. The helper macro BT_GATT_SERVICE() can be used to declare a service.

Attributes can be declared using the bt_gatt_attr struct or using one of the helper macros:

BT_GATT_PRIMARY_SERVICE()

Declares a Primary Service.

BT_GATT_SECONDARY_SERVICE()

Declares a Secondary Service.

BT_GATT_INCLUDE_SERVICE()

Declares a Include Service.

BT_GATT_CHARACTERISTIC()

Declares a Characteristic.

BT_GATT_DESCRIPTOR()

Declares a Descriptor.

BT_GATT_ATTRIBUTE()

Declares an Attribute.

BT_GATT_CCC()

Declares a Client Characteristic Configuration.

BT_GATT_CEP()

Declares a Characteristic Extended Properties.

BT_GATT_CUD()

Declares a Characteristic User Format.

Each attribute contain a uuid, which describes their type, a read callback, a write callback and a set of permission. Both read and write callbacks can be set to NULL if the attribute permission don鈥檛 allow their respective operations.

Note

Attribute read and write callbacks are called directly from RX Thread thus it is not recommended to block for long periods of time in them.

Attribute value changes can be notified using bt_gatt_notify() API, alternatively there is bt_gatt_notify_cb() where is is possible to pass a callback to be called when it is necessary to know the exact instant when the data has been transmitted over the air. Indications are supported by bt_gatt_indicate() API.

Client procedures can be enabled with the configuration option: CONFIG_BT_GATT_CLIENT

Discover procedures can be initiated with the use of bt_gatt_discover() API which takes the bt_gatt_discover_params struct which describes the type of discovery. The parameters also serves as a filter when setting the uuid field only attributes which matches will be discovered, in contrast setting it to NULL allows all attributes to be discovered.

Note

Caching discovered attributes is not supported.

Read procedures are supported by bt_gatt_read() API which takes the bt_gatt_read_params struct as parameters. In the parameters one or more attributes can be set, though setting multiple handles requires the option: CONFIG_BT_GATT_READ_MULTIPLE

Write procedures are supported by bt_gatt_write() API and takes bt_gatt_write_params struct as parameters. In case the write operation don鈥檛 require a response bt_gatt_write_without_response() or bt_gatt_write_without_response_cb() APIs can be used, with the later working similarly to bt_gatt_notify_cb.

Subscriptions to notification and indication can be initiated with use of :cpp:func`bt_gatt_subscribe` API which takes bt_gatt_subscribe_params as parameters. Multiple subscriptions to the same attribute are supported so there could be multiple notify callback being triggered for the same attribute. Subscriptions can be removed with use of bt_gatt_unsubscribe() API.

Note

When subscriptions are removed notify callback is called with the data set to NULL.

API Reference露 group bt_gatt

Generic Attribute Profile (GATT)

Defines

BT_GATT_ERR(_att_err)露

Construct error return value for attribute read and write callbacks.

Return

Appropriate error code for the attribute callbacks.

Parameters

_att_err: ATT error code

BT_GATT_CHRC_BROADCAST露

Characteristic broadcast property.

If set, permits broadcasts of the Characteristic Value using Server Characteristic Configuration Descriptor.

BT_GATT_CHRC_READ露

Characteristic read property.

If set, permits reads of the Characteristic Value.

BT_GATT_CHRC_WRITE_WITHOUT_RESP露

Characteristic write without response property.

If set, permits write of the Characteristic Value without response.

BT_GATT_CHRC_WRITE露

Characteristic write with response property.

If set, permits write of the Characteristic Value with response.

BT_GATT_CHRC_NOTIFY露

Characteristic notify property.

If set, permits notifications of a Characteristic Value without acknowledgment.

BT_GATT_CHRC_INDICATE露

Characteristic indicate property.

If set, permits indications of a Characteristic Value with acknowledgment.

BT_GATT_CHRC_AUTH露

Characteristic Authenticated Signed Writes property.

If set, permits signed writes to the Characteristic Value.

BT_GATT_CHRC_EXT_PROP露

Characteristic Extended Properties property.

If set, additional characteristic properties are defined in the Characteristic Extended Properties Descriptor.

BT_GATT_CEP_RELIABLE_WRITE露 BT_GATT_CEP_WRITABLE_AUX露 BT_GATT_CCC_NOTIFY露

Client Characteristic Configuration Notification.

If set, changes to Characteristic Value shall be notified.

BT_GATT_CCC_INDICATE露

Client Characteristic Configuration Indication.

If set, changes to Characteristic Value shall be indicated.

Enums

enum [anonymous]露

Values:

BT_GATT_PERM_NONE = 0露

No operations supported, e.g. for notify-only

BT_GATT_PERM_READ = BIT(0)露

Attribute read permission.

BT_GATT_PERM_WRITE = BIT(1)露

Attribute write permission.

BT_GATT_PERM_READ_ENCRYPT = BIT(2)露

Attribute read permission with encryption.

If set, requires encryption for read access. BT_GATT_PERM_WRITE_ENCRYPT = BIT(3)露

Attribute write permission with encryption.

If set, requires encryption for write access. BT_GATT_PERM_READ_AUTHEN = BIT(4)露

Attribute read permission with authentication.

If set, requires encryption using authenticated link-key for read access. BT_GATT_PERM_WRITE_AUTHEN = BIT(5)露

Attribute write permission with authentication.

If set, requires encryption using authenticated link-key for write access. BT_GATT_PERM_PREPARE_WRITE = BIT(6)露

Attribute prepare write permission.

If set, allows prepare writes with use of BT_GATT_WRITE_FLAG_PREPARE passed to write callback. enum [anonymous]露

Values:

BT_GATT_WRITE_FLAG_PREPARE = BIT(0)露

Attribute prepare write flag

If set, write callback should only check if the device is authorized but no data shall be written. BT_GATT_WRITE_FLAG_CMD = BIT(1)露

Attribute write command flag

If set, indicates that write operation is a command (Write without response) which doesn't generate any response. struct bt_gatt_attr露 #include

GATT Attribute structure.

struct bt_gatt_service_static露 #include

GATT Service structure.

struct bt_gatt_service露 #include

GATT Service structure.

struct bt_gatt_service_val露 #include

Service Attribute Value.

struct bt_gatt_include露 #include

Include Attribute Value.

struct bt_gatt_chrc露 #include

Characteristic Attribute Value.

struct bt_gatt_cep露 #include

Characteristic Extended Properties Attribute Value.

struct bt_gatt_cpf露 #include

GATT Characteristic Presentation Format Attribute Value.

GATT Server露 group bt_gatt_server

Defines

BT_GATT_SERVICE_DEFINE(_name, ...)露

Statically define and register a service.

Helper macro to statically define and register a service.

Parameters

_name: Service name.

BT_GATT_SERVICE(_attrs)露

Service Structure Declaration Macro.

Helper macro to declare a service structure.

Parameters

_attrs: Service attributes.

BT_GATT_PRIMARY_SERVICE(_service)露

Primary Service Declaration Macro.

Helper macro to declare a primary service attribute.

Parameters

_service: Service attribute value.

BT_GATT_SECONDARY_SERVICE(_service)露

Secondary Service Declaration Macro.

Helper macro to declare a secondary service attribute.

Parameters

_service: Service attribute value.

BT_GATT_INCLUDE_SERVICE(_service_incl)露

Include Service Declaration Macro.

Helper macro to declare database internal include service attribute.

Parameters

_service_incl: the first service attribute of service to include

BT_GATT_CHARACTERISTIC(_uuid, _props, _perm, _read, _write, _value)露

Characteristic and Value Declaration Macro.

Helper macro to declare a characteristic attribute along with its attribute value.

Parameters

_uuid: Characteristic attribute uuid.

_props: Characteristic attribute properties.

_perm: Characteristic Attribute access permissions.

_read: Characteristic Attribute read callback.

_write: Characteristic Attribute write callback.

_value: Characteristic Attribute value.

BT_GATT_CCC_MAX露 BT_GATT_CCC_INITIALIZER(_changed, _write, _match)露

Initialize Client Characteristic Configuration Declaration Macro.

Helper macro to initialize a Managed CCC attribute value.

Parameters

_changed: Configuration changed callback.

_write: Configuration write callback.

_match: Configuration match callback.

BT_GATT_CCC_MANAGED(_ccc, _perm)露

Managed Client Characteristic Configuration Declaration Macro.

Helper macro to declare a Managed CCC attribute.

Parameters

_ccc: CCC attribute user data, shall point to a _bt_gatt_ccc.

_perm: CCC access permissions.

BT_GATT_CCC(_changed, _perm)露

Client Characteristic Configuration Declaration Macro.

Helper macro to declare a CCC attribute.

Parameters

_changed: Configuration changed callback.

_perm: CCC access permissions.

BT_GATT_CEP(_value)露

Characteristic Extended Properties Declaration Macro.

Helper macro to declare a CEP attribute.

Parameters

_value: Descriptor attribute value.

BT_GATT_CUD(_value, _perm)露

Characteristic User Format Descriptor Declaration Macro.

Helper macro to declare a CUD attribute.

Parameters

_value: User description NULL-terminated C string.

_perm: Descriptor attribute access permissions.

BT_GATT_CPF(_value)露

Characteristic Presentation Format Descriptor Declaration Macro.

Helper macro to declare a CPF attribute.

Parameters

_value: Descriptor attribute value.

BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _value)露

Descriptor Declaration Macro.

Helper macro to declare a descriptor attribute.

Parameters

_uuid: Descriptor attribute uuid.

_perm: Descriptor attribute access permissions.

_read: Descriptor attribute read callback.

_write: Descriptor attribute write callback.

_value: Descriptor attribute value.

BT_GATT_ATTRIBUTE(_uuid, _perm, _read, _write, _value)露

Attribute Declaration Macro.

Helper macro to declare an attribute.

Parameters

_uuid: Attribute uuid.

_perm: Attribute access permissions.

_read: Attribute read callback.

_write: Attribute write callback.

_value: Attribute value.

Typedefs

typedef bt_gatt_attr_func_t露

Attribute iterator callback.

Return

BT_GATT_ITER_CONTINUE if should continue to the next attribute or BT_GATT_ITER_STOP to stop.

Parameters

attr: Attribute found.

user_data: Data given.

typedef void (*bt_gatt_complete_func_t)(struct bt_conn *conn, void *user_data)露

Notification complete result callback.

Parameters

conn: Connection object.

typedef bt_gatt_indicate_func_t露

Indication complete result callback.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

attr: Attribute object.

err: ATT error code

Enums

enum [anonymous]露

Values:

BT_GATT_ITER_STOP = 0露 BT_GATT_ITER_CONTINUE露

Functions

int bt_gatt_service_register(struct bt_gatt_service *svc)露

Register GATT service.

Register GATT service. Applications can make use of macros such as BT_GATT_PRIMARY_SERVICE, BT_GATT_CHARACTERISTIC, BT_GATT_DESCRIPTOR, etc.

Return

0 in case of success or negative value in case of error.

Parameters

svc: Service containing the available attributes

int bt_gatt_service_unregister(struct bt_gatt_service *svc)露

Unregister GATT service. *.

Return

0 in case of success or negative value in case of error.

Parameters

svc: Service to be unregistered.

void bt_gatt_foreach_attr_type(u16_t start_handle, u16_t end_handle, const struct bt_uuid *uuid, const void *attr_data, uint16_t num_matches, bt_gatt_attr_func_t func, void *user_data)露

Attribute iterator by type.

Iterate attributes in the given range matching given UUID and/or data.

Parameters

start_handle: Start handle.

end_handle: End handle.

uuid: UUID to match, passing NULL skips UUID matching.

attr_data: Attribute data to match, passing NULL skips data matching.

num_matches: Number matches, passing 0 makes it unlimited.

func: Callback function.

user_data: Data to pass to the callback.

static void bt_gatt_foreach_attr(u16_t start_handle, u16_t end_handle, bt_gatt_attr_func_t func, void *user_data)露

Attribute iterator.

Iterate attributes in the given range.

Parameters

start_handle: Start handle.

end_handle: End handle.

func: Callback function.

user_data: Data to pass to the callback.

struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr)露

Iterate to the next attribute.

Iterate to the next attribute following a given attribute.

Return

The next attribute or NULL if it cannot be found.

Parameters

attr: Current Attribute.

uint16_t bt_gatt_attr_value_handle(const struct bt_gatt_attr *attr)露

Get the handle of the characteristic value descriptor.

Return

the handle of the corresponding Characteristic Value. The value will be zero (the invalid handle) if attr was not a characteristic attribute.

Parameters

attr: A Characteristic Attribute

ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t buf_len, u16_t offset, const void *value, u16_t value_len)露

Generic Read Attribute value helper.

Read attribute value from local database storing the result into buffer.

Return

int number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object.

attr: Attribute to read.

buf: Buffer to store the value.

buf_len: Buffer length.

offset: Start offset.

value: Attribute value.

value_len: Length of the attribute value.

ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Service Attribute helper.

Read service attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a bt_uuid.

Return

int number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object.

attr: Attribute to read.

buf: Buffer to store the value read.

len: Buffer length.

offset: Start offset.

ssize_t bt_gatt_attr_read_included(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Include Attribute helper.

Read include service attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a bt_gatt_include.

Return

int number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object.

attr: Attribute to read.

buf: Buffer to store the value read.

len: Buffer length.

offset: Start offset.

ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Characteristic Attribute helper.

Read characteristic attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a bt_gatt_chrc.

Return

number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object.

attr: Attribute to read.

buf: Buffer to store the value read.

len: Buffer length.

offset: Start offset.

ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Client Characteristic Configuration Attribute helper.

Read CCC attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a _bt_gatt_ccc.

Return

number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object.

attr: Attribute to read.

buf: Buffer to store the value read.

len: Buffer length.

offset: Start offset.

ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags)露

Write Client Characteristic Configuration Attribute helper.

Write value in the buffer into CCC attribute. NOTE: Only use this with attributes which user_data is a _bt_gatt_ccc.

Return

number of bytes written in case of success or negative values in case of error.

Parameters

conn: Connection object.

attr: Attribute to read.

buf: Buffer to store the value read.

len: Buffer length.

offset: Start offset.

flags: Write flags.

ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Characteristic Extended Properties Attribute helper.

Read CEP attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a bt_gatt_cep.

Return

number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object

attr: Attribute to read

buf: Buffer to store the value read

len: Buffer length

offset: Start offset

ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Characteristic User Description Descriptor Attribute helper.

Read CUD attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a NULL-terminated C string.

Return

number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object

attr: Attribute to read

buf: Buffer to store the value read

len: Buffer length

offset: Start offset

ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, u16_t len, u16_t offset)露

Read Characteristic Presentation format Descriptor Attribute helper.

Read CPF attribute value from local database storing the result into buffer after encoding it. NOTE: Only use this with attributes which user_data is a bt_gatt_pf.

Return

number of bytes read in case of success or negative values in case of error.

Parameters

conn: Connection object

attr: Attribute to read

buf: Buffer to store the value read

len: Buffer length

offset: Start offset

int bt_gatt_notify_cb(struct bt_conn *conn, struct bt_gatt_notify_params *params)露

Notify attribute value change.

This function works in the same way as bt_gatt_notify. With the addition that after sending the notification the callback function will be called.

The callback is run from System Workqueue context.

Alternatively it is possible to notify by UUID by setting it on the parameters, when using this method the attribute given is used as the start range when looking up for possible matches.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Notification parameters.

static int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *data, u16_t len)露

Notify attribute value change.

Send notification of attribute value change, if connection is NULL notify all peer that have notification enabled via CCC otherwise do a direct notification only the given connection.

The attribute object on the parameters can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

attr: Characteristic or Characteristic Value attribute.

data: Pointer to Attribute data.

len: Attribute value length.

int bt_gatt_indicate(struct bt_conn *conn, struct bt_gatt_indicate_params *params)露

Indicate attribute value change.

Send an indication of attribute value change. if connection is NULL indicate all peer that have notification enabled via CCC otherwise do a direct indication only the given connection.

The attribute object on the parameters can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC.

The callback is run from System Workqueue context.

Alternatively it is possible to indicate by UUID by setting it on the parameters, when using this method the attribute given is used as the start range when looking up for possible matches.

Note: This procedure is asynchronous therefore the parameters need to remains valid while it is active.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Indicate parameters.

bool bt_gatt_is_subscribed(struct bt_conn *conn, const struct bt_gatt_attr *attr, u16_t ccc_value)露

Check if connection have subscribed to attribute.

Check if connection has subscribed to attribute value change.

The attribute object can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC, or the Client Characteristic Configuration Descriptor (CCCD) which is created by BT_GATT_CCC.

Return

true if the attribute object has been subscribed.

Parameters

conn: Connection object.

attr: Attribute object.

ccc_value: The subscription type, either notifications or indications.

u16_t bt_gatt_get_mtu(struct bt_conn *conn)露

Get ATT MTU for a connection.

Get negotiated ATT connection MTU, note that this does not equal the largest amount of attribute data that can be transferred within a single packet.

Return

MTU in bytes

Parameters

conn: Connection object.

struct bt_gatt_ccc_cfg露 #include

GATT CCC configuration entry.

Parameters

id: Local identity, BT_ID_DEFAULT in most cases.

peer: Remote peer address

value: Configuration value.

data: Configuration pointer data.

struct bt_gatt_indicate_params露 #include

GATT Indicate Value parameters.

GATT Client露 group bt_gatt_client

Typedefs

typedef bt_gatt_discover_func_t露

Discover attribute callback function.

If discovery procedure has completed this callback will be called with attr set to NULL. This will not happen if procedure was stopped by returning BT_GATT_ITER_STOP. The attribute is read-only and cannot be cached without copying its contents.

Parameters

conn: Connection object.

attr: Attribute found.

params: Discovery parameters given.

Return

BT_GATT_ITER_CONTINUE if should continue attribute discovery or BT_GATT_ITER_STOP to stop discovery procedure.

typedef bt_gatt_read_func_t露

Read callback function.

Parameters

conn: Connection object.

err: ATT error code.

params: Read parameters used.

data: Attribute value data. NULL means read has completed.

length: Attribute value length.

typedef bt_gatt_write_func_t露

Write callback function.

Parameters

conn: Connection object.

err: ATT error code.

params: Write parameters used.

typedef bt_gatt_notify_func_t露

Notification callback function.

Parameters

conn: Connection object. May be NULL, indicating that the peer is being unpaired

params: Subscription parameters.

data: Attribute value data. If NULL then subscription was removed.

length: Attribute value length.

Enums

enum [anonymous]露

Values:

BT_GATT_DISCOVER_PRIMARY露

Discover Primary Services.

BT_GATT_DISCOVER_SECONDARY露

Discover Secondary Services.

BT_GATT_DISCOVER_INCLUDE露

Discover Included Services.

BT_GATT_DISCOVER_CHARACTERISTIC露

Discover Characteristic Values.

Discover Characteristic Value and its properties. BT_GATT_DISCOVER_DESCRIPTOR露

Discover Descriptors.

Discover Attributes which are not services or characteristics. Note: The use of this type of discover is not recommended for discovering in ranges across multiple services/characteristics as it may incur in extra round trips. BT_GATT_DISCOVER_ATTRIBUTE露

Discover Attributes.

Discover Attributes of any type. Note: The use of this type of discover is not recommended for discovering in ranges across multiple services/characteristics as it may incur in more round trips. enum [anonymous]露

Values:

BT_GATT_SUBSCRIBE_FLAG_VOLATILE露

Persistence flag

If set, indicates that the subscription is not saved on the GATT server side. Therefore, upon disconnection, the subscription will be automatically removed from the client's subscriptions list and when the client reconnects, it will have to issue a new subscription. BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING露

Write pending flag

If set, indicates write operation is pending waiting remote end to respond. BT_GATT_SUBSCRIBE_NUM_FLAGS露

Functions

int bt_gatt_exchange_mtu(struct bt_conn *conn, struct bt_gatt_exchange_params *params)露

Exchange MTU.

This client procedure can be used to set the MTU to the maximum possible size the buffers can hold.

NOTE: Shall only be used once per connection.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Exchange MTU parameters.

int bt_gatt_discover(struct bt_conn *conn, struct bt_gatt_discover_params *params)露

GATT Discover function.

This procedure is used by a client to discover attributes on a server.

Primary Service Discovery: Procedure allows to discover specific Primary Service based on UUID. Include Service Discovery: Procedure allows to discover all Include Services within specified range. Characteristic Discovery: Procedure allows to discover all characteristics within specified handle range as well as discover characteristics with specified UUID. Descriptors Discovery: Procedure allows to discover all characteristic descriptors within specified range.

For each attribute found the callback is called which can then decide whether to continue discovering or stop.

Note: This procedure is asynchronous therefore the parameters need to remains valid while it is active.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Discover parameters.

int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params)露

Read Attribute Value by handle.

This procedure read the attribute value and return it to the callback.

When reading attributes by UUID the callback can be called multiple times depending on how many instances of given the UUID exists with the start_handle being updated for each instance.

If an instance does contain a long value which cannot be read entirely the caller will need to read the remaining data separately using the handle and offset.

Note: This procedure is asynchronous therefore the parameters need to remains valid while it is active.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Read parameters.

int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params)露

Write Attribute Value by handle.

This procedure write the attribute value and return the result in the callback.

Note: This procedure is asynchronous therefore the parameters need to remains valid while it is active.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Write parameters.

int bt_gatt_write_without_response_cb(struct bt_conn *conn, u16_t handle, const void *data, u16_t length, bool sign, bt_gatt_complete_func_t func, void *user_data)露

Write Attribute Value by handle without response with callback.

This function works in the same way as bt_gatt_write_without_response. With the addition that after sending the write the callback function will be called.

The callback is run from System Workqueue context.

Note: By using a callback it also disable the internal flow control which would prevent sending multiple commands without waiting for their transmissions to complete, so if that is required the caller shall not submit more data until the callback is called.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

handle: Attribute handle.

data: Data to be written.

length: Data length.

sign: Whether to sign data

func: Transmission complete callback.

user_data: User data to be passed back to callback.

static int bt_gatt_write_without_response(struct bt_conn *conn, u16_t handle, const void *data, u16_t length, bool sign)露

Write Attribute Value by handle without response.

This procedure write the attribute value without requiring an acknowledgment that the write was successfully performed

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

handle: Attribute handle.

data: Data to be written.

length: Data length.

sign: Whether to sign data

int bt_gatt_subscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *params)露

Subscribe Attribute Value Notification.

This procedure subscribe to value notification using the Client Characteristic Configuration handle. If notification received subscribe value callback is called to return notified value. One may then decide whether to unsubscribe directly from this callback. Notification callback with NULL data will not be called if subscription was removed by this method.

Note: This procedure is asynchronous therefore the parameters need to remains valid while it is active.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Subscribe parameters.

int bt_gatt_unsubscribe(struct bt_conn *conn, struct bt_gatt_subscribe_params *params)露

Unsubscribe Attribute Value Notification.

This procedure unsubscribe to value notification using the Client Characteristic Configuration handle. Notification callback with NULL data will be called if subscription was removed by this call, until then the parameters cannot be reused.

Return

0 in case of success or negative value in case of error.

Parameters

conn: Connection object.

params: Subscribe parameters.

void bt_gatt_cancel(struct bt_conn *conn, void *params)露

Cancel GATT pending request.

Parameters

conn: Connection object.

params: Requested params address.

struct bt_gatt_exchange_params露 #include

GATT Exchange MTU parameters.

struct bt_gatt_discover_params露 #include

GATT Discover Attributes parameters.

struct bt_gatt_read_params露 #include

GATT Read parameters.

Parameters

func: Read attribute callback

handle_count: If equals to 1 single.handle and single.offset are used. If >1 Read Multiple Characteristic Values is performed and handles are used. If equals to 0 by_uuid is used for Read Using Characteristic UUID.

handle: Attribute handle

offset: Attribute data offset

handles: Handles to read in Read Multiple Characteristic Values

start_handle: First requested handle number

end_handle: Last requested handle number

uuid: 2 or 16 octet UUID

struct bt_gatt_write_params露 #include

GATT Write parameters.

struct bt_gatt_subscribe_params露 #include

GATT Subscribe parameters.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有